home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Filling Shapes with a Gradient Brush / Creating a Path Gradient / Customizing a Path Gradient / APP2 / GDITEST80.dpr
Encoding:
Text File  |  2003-10-15  |  2.9 KB  |  108 lines

  1. program GDITEST80;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10.  
  11. Procedure OnPaint(DC: HDC);
  12. var
  13.   graphics : TGPGraphics;
  14.   points: array[0..2] of TGPPoint;
  15.   pthGrBrush: TGPPathGradientBrush;
  16. const
  17.   presetColors: array[0..2] of TGPColor = (aclGreen, aclAqua, aclBlue);
  18.   interpPositions: array[0..2] of Single = (0.0, 0.25, 1.0);
  19. begin
  20.   graphics := TGPGraphics.Create(DC);
  21.  
  22.   // Vertices of the triangle
  23.   points[0] := MakePoint(100, 0);
  24.   points[1] := MakePoint(200, 200);
  25.   points[2] := MakePoint(0, 200);
  26.  
  27.   // No GraphicsPath object is created. The PathGradient
  28.   // brush is constructed directly from the array of points.
  29.   pthGrBrush:= TGPPathGradientBrush.Create(PGPPoint(@points), 3);
  30.  
  31.   pthGrBrush.SetInterpolationColors(@presetColors, @interpPositions, 3);
  32.  
  33.   // Fill a rectangle that is larger than the triangle
  34.   // specified in the Point array. The portion of the
  35.   // rectangle outside the triangle will not be painted.
  36.   graphics.FillRectangle(pthGrBrush, 0, 0, 200, 200);
  37.  
  38.   pthGrBrush.Free;
  39.   graphics.Free;
  40. end;
  41.  
  42.  
  43. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  44. var
  45.   Handle: HDC;
  46.   ps: PAINTSTRUCT;
  47. begin
  48.   case message of
  49.     WM_PAINT:
  50.       begin
  51.         Handle := BeginPaint(Wnd, ps);
  52.         OnPaint(Handle);
  53.         EndPaint(Wnd, ps);
  54.         result := 0;
  55.       end;
  56.  
  57.     WM_DESTROY:
  58.       begin
  59.         PostQuitMessage(0);
  60.         result := 0;
  61.       end;
  62.  
  63.    else
  64.       result := DefWindowProc(Wnd, message, wParam, lParam);
  65.    end;
  66. end;
  67.  
  68. var
  69.   hWnd     : THandle;
  70.   Msg      : TMsg;
  71.   wndClass : TWndClass;
  72. begin
  73.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  74.    wndClass.lpfnWndProc    := @WndProc;
  75.    wndClass.cbClsExtra     := 0;
  76.    wndClass.cbWndExtra     := 0;
  77.    wndClass.hInstance      := hInstance;
  78.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  79.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  80.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  81.    wndClass.lpszMenuName   := nil;
  82.    wndClass.lpszClassName  := 'GettingStarted';
  83.  
  84.    RegisterClass(wndClass);
  85.  
  86.    hWnd := CreateWindow(
  87.       'GettingStarted',       // window class name
  88.       'Customizing a Path Gradient',       // window caption
  89.       WS_OVERLAPPEDWINDOW,    // window style
  90.       Integer(CW_USEDEFAULT), // initial x position
  91.       Integer(CW_USEDEFAULT), // initial y position
  92.       Integer(CW_USEDEFAULT), // initial x size
  93.       Integer(CW_USEDEFAULT), // initial y size
  94.       0,                      // parent window handle
  95.       0,                      // window menu handle
  96.       hInstance,              // program instance handle
  97.       nil);                   // creation parameters
  98.  
  99.    ShowWindow(hWnd, SW_SHOW);
  100.    UpdateWindow(hWnd);
  101.  
  102.    while(GetMessage(msg, 0, 0, 0)) do
  103.    begin
  104.       TranslateMessage(msg);
  105.       DispatchMessage(msg);
  106.    end;
  107. end.
  108.